<template>
	<view>
		<!-- 待接单 -->
		<state0 v-if="orderForm.managestate == '待接单'" :orderId="id" :orderForm="orderForm" @update="update"></state0>
		<!-- 已接单 -->
		<state1 v-if="orderForm.managestate == '已接单'" :orderId="id" :orderForm="orderForm" @update="update"></state1>
		<!-- 待上门 -->
		<state2 v-if="orderForm.managestate == '待上门'" :orderId="id" :orderForm="orderForm" @update="update"></state2>
		<!-- 待付款 -->
		<state3 v-if="orderForm.managestate == '待付款'" :orderId="id" :orderForm="orderForm" @update="update"></state3>
		<!-- 已取消 -->
		<state4 v-if="orderForm.managestate == '已取消'" :orderId="id" :orderForm="orderForm" @update="update"></state4>
		<!-- 已回收、待入库、已入库 -->
		<state5 v-if="orderForm.managestate == '已回收' || orderForm.managestate == '待入库' || orderForm.managestate == '已入库'" :orderId="id" :orderForm="orderForm" @update="update"></state5>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapActions
	} from 'vuex';

	import state0 from './components/orderState/state-0.vue'
	import state1 from './components/orderState/state-1.vue'
	import state2 from './components/orderState/state-2.vue'
	import state3 from './components/orderState/state-3.vue'
	import state4 from './components/orderState/state-4.vue'
	import state5 from './components/orderState/state-5.vue'
	
	export default {
		components:{
			// amap,
			state0,
			state1,
			state2,
			state3,
			state4,
			state5,
		},
		data() {
			return {
				id: 0,
				orderForm: {},
				list: [
					{
						"value": 1,
						"name": "待接单"
					}, 
					{
						"value": 2,
						"name": "已接单"
					}, 
					{
						"value": 3,
						"name": "待上门",
					}, 
					{
						"value": 4,
						"name": "待付款",
					}, 
					{
						"value": 5,
						"name": "已取消",
					}, 
					{
						"value": 6,
						"name": "已回收",
					}, 
					{
						"value": 7,
						"name": "待入库",
					}, 
					{
						"value": 8,
						"name": "已入库",
					}
				],
			}
		},
		computed: {
			...mapState({
				userdetail: state => state.userdetail,
				header: state => state.Authorization
			})
		},
		onPullDownRefresh() {
			this.orderView(this.id).then(()=>{
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		onLoad(opt) {
			this.id = opt.id
			this.orderView(this.id).then(()=>{
				if(opt.address){
					console.log(JSON.parse(opt.address))
					let address = JSON.parse(opt.address)
					console.log('this.orderForm.address:',this.orderForm.address)
					this.orderForm.address.lng = address.location.longitude
					this.orderForm.address.lat = address.location.latitude
					this.orderForm.address.address = address.name
					// this.orderForm.address.name = '老王'
					this.edit(this.orderForm,this.id)
				}
			})
		},
		// 在页面中直接使用uni-app生命周期函数
		onBackPress(options) {
		    console.log('监听到返回操作', options.from);
		    
		    // 执行你的业务逻辑（比如数据清理）
		    this.$store.commit('brother/setGoodsDetails', []);
		
		    // 阻止默认返回行为（需要返回true）
		    // return true; 
		    
		    // 允许默认返回（返回false或不返回）
		    return false;
		},
		methods: {
			// 订单详情
			orderView(id){
				return this.$u.get('/User/Order/Detail?id='+id).then((res)=>{
					// res.managestateName = this.list.find((item)=>item.value == res.managestate).name
					this.orderForm = res
				}).catch(res=>{
					uni.showModal({
						title: '提示',
						content: '订单不存在或者错误',
						showCancel:false,
						success: function (res) {
							// if (res.confirm) {
							// 	uni.redirectTo({
							// 		url: '/pages/news/news'
							// 	});
							// }
						}
					});
				})
			},
			// 修改上门时间与地址
			edit(orderForm,id){
				orderForm.address.cityid = orderForm.address.citypath.split(',')[3]
				
				this.$u.post('/Brother/UserOrder/edit',{
					id: id,
					doortime: orderForm.doortime,
					address: orderForm.address
				}).then((res)=>{
					uni.showToast({
						title: res.msg
					})
					this.$emit('update')
				})
			},
			update(){
				this.orderView(this.id)
			},
			confirmChoose(confirmForm){
				console.log('view页面里',confirmForm)
			}
		}
	}
</script>

<style lang="scss" scoped>
	// ::v-deep{
	// 	.order-views{
	// 		padding-bottom: 30rpx;
	// 	}
	// }
</style>
